package com.alliky.core.base

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.alibaba.android.arouter.launcher.ARouter
import com.rrc.common.api.BaseApi
import com.alliky.core.utils.RxUtils
import com.alliky.core.BuildConfig
import com.alliky.core.config.AppConfig
import com.alliky.core.log.KLog
import com.scwang.smartrefresh.header.WaterDropHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
import com.tamsiree.rxkit.RxTool

/**
 * ================================================
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2022/11/4 13:53
 * ================================================
 */
open class BaseApplication : Application() {

    private var isDebug = BuildConfig.DEBUG

    override fun onCreate() {
        super.onCreate()
        KLog.init(isDebug)
        if (isDebug) {
            ARouter.openLog()
            ARouter.openDebug()
        }

        ARouter.init(this)
        RxTool.init(this)
        RxUtils.init(this)
        AppConfig.init(this)
            .withLoaderDelayed(500)
            .withApiHost(BaseApi.API_HOST)
//            .withWeChatAppId(Global.ThirdPlatform.WECHAT_APP_ID)
//            .withWeChatAppSecret(Global.ThirdPlatform.WECHAT_APP_SECRET)
            .configure()

        initSmartRefreshLayout()

    }

    //初始化SmartRefreshLayout
    private fun initSmartRefreshLayout() {
        SmartRefreshLayout.setDefaultRefreshInitializer { context, layout ->
            layout.setRefreshHeader(WaterDropHeader(context))
            layout.setRefreshFooter(ClassicsFooter(context))
        }
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(base)
    }
}